attribute vec3 a_posL;
attribute vec2 a_uv;
attribute vec3 a_normal;

uniform mat4 u_mvp;
uniform mat4 u_matTransposeInverseViewModel;
uniform mat4 matViewModel; 
uniform vec3 Camera_Position; 


varying vec2 v_uv;
varying vec4 v_ambient;
varying vec4 v_diffuse;
varying vec4 v_specular; 

void main()
{

	 vec3 light_position=vec3(1.0,1.0, 1.0);
	 vec4 light_ambient=vec4(0.3, 0.3, 0.3, 1.0);
	 vec4 light_diffuse=vec4(0.9, 0.9, 0.9, 1.0);
	 vec4 light_specular=vec4(1.0);
	 
	float light_constantAttenuation=0.5; 
    float light_linearAttenuation=0.9; 
    float light_quadraticAttenuation=0.5; 
    
     float Material_shininess=64.0; 
     
	vec4 posL = u_mvp * vec4(a_posL, 1.0);
	gl_Position = posL;
	v_uv = a_uv;
	
	//Get position of current vertex after transform 
	vec3 currentVertexPos = (matViewModel*vec4(a_posL, 0.0)).xyz; 
	
	//Get light vector L of current vertex 
   vec3 normalVector = normalize(mat3(u_matTransposeInverseViewModel)*a_normal);
   
   //Get distance between of Light and vertex 
   float distance = length(light_position-currentVertexPos); 
   
   vec3 currentlightVector = normalize(light_position -currentVertexPos); 
   float NDotL = max( 0.0 , dot(normalVector, currentlightVector));
   
   //Get Attenuation of light (strength of light) 
   float attenuation =  1.0/(light_constantAttenuation +light_linearAttenuation * distance + light_quadraticAttenuation * distance * distance); 
   v_diffuse = light_diffuse * NDotL* attenuation;
   v_ambient = light_ambient;
   
   /////////////////////
   vec3 eyeVector = normalize(Camera_Position-currentVertexPos); 
   vec3 reflectVector = normalize(reflect(currentlightVector,normalVector)); 
   float RdotE = max(0.0, dot(eyeVector, reflectVector)); 
   float reflectPower = pow(RdotE, Material_shininess); 
   v_specular = clamp(light_specular * reflectPower, 0.0, 1.0) *  attenuation;
}